import axios, { AxiosResponse, AxiosRequestConfig } from 'axios'

const instance = axios.create()

// Request interceptors
instance.interceptors.request.use(
  (config: AxiosRequestConfig) => {
    // do something
    return config;
  },
  (error: any) => {
    Promise.reject(error);
  }
)

// Response interceptors
instance.interceptors.response.use(
  async (response: AxiosResponse): Promise<any> => {
    // do something
    console.log(response)
    return response
  },
  (error: any) => {
    if (error && error.response) {
      // do something
    } else {
      if (error.message == 'Network Error') {
        error.message == '网络异常！';
      }
      error.message = '网络异常';
    }
    return Promise.reject(error);
  }
)

export default instance